package com.flame.auth.core.context;

import com.flame.auth.core.entity.TrustedPrincipal;

/**
 * AuthContextHolder
 *
 * @author wuxintong
 * @since 2022/11/28
 */
public final class AuthContextHolder {

    private AuthContextHolder() {
    }

    private static final ThreadLocal<TrustedPrincipal> AUTH_CONTEXT_HOLDER = new ThreadLocal<>();

    public static void setContext(TrustedPrincipal trustedPrincipal) {
        AUTH_CONTEXT_HOLDER.set(trustedPrincipal);
    }

    public static TrustedPrincipal getContext() {
        return AUTH_CONTEXT_HOLDER.get();
    }

    public static void clear() {
        AUTH_CONTEXT_HOLDER.remove();
    }
}
